package edu.gdpu.classloader;

import com.sun.crypto.provider.AESKeyGenerator;

import java.lang.reflect.Method;

/**
 * @author mazebin
 * @date 2021年 07月08日 15:38:32
 * 各加载器的路径是可以修改的，修改后会导致运行失败，ClassNotFoundExeception
 */
public class ClassLoaderTest20 {
    public static void main(String[] args) throws Exception {
        CustomClassLoader loader = new CustomClassLoader();
        CustomClassLoader loader1 = new CustomClassLoader();
        loader.setPath("D:\\testClass\\");
        loader1.setPath("D:\\testClass\\");
        Class<?> clazz = loader.loadClass("edu.gdpu.classloader.Person");
        Class<?> aClass = loader1.loadClass("edu.gdpu.classloader.Person");
        //clazz1和clazz均由应用类加载器加载的，第二次不会重新加载，结果为true
        System.out.println(aClass == clazz);
        System.out.println(aClass.getClassLoader() == clazz.getClassLoader());
        System.out.println(aClass.getClassLoader());
        Object o =  clazz.newInstance();
        Object o1 = aClass.newInstance();
        Method method = aClass.getMethod("setPerson",Object.class);
        method.invoke(o,o1);


    }
}
